<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('用户答卷列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>答卷：</label>
                                <input type="text" name="wenjuan.title"/>
                            </li>
                            
                            <li>
                                <label>用户：</label>
                                <input type="text" name="createBy"/>
                            </li>
                            <li class="select-time">
                                <label>答题时间：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginCreateTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endCreateTime]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
            
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:dajuan:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>

            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:dajuan:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:dajuan:remove')}]];

        var pingfenFlag = [[${@permission.hasAnyRoles('admin,user')}]];
        var staffFlag = [[${@permission.hasRole('staff')}]];
        var prefix = ctx + "system/dajuan";
        var wprefix = ctx + "system/wenjuan";

        var pingfenprefix = ctx + "system/pingfen";
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "用户问卷",
                pageSize:9999,
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'wenjuan.title',
                    title: '问卷'
                }, 
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                       return value=="0"?"未答题":"已答题";
                    }
                }, 
                {
                    field: 'score',
                    title: '分数'
                },
                {
                    field: 'rank',
                    title: '排名',
                },
                {
                    field: 'createBy',
                    title: '用户'
                },
                {
                    field: 'createTime',
                    title: '答题时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
						if(row.status == 0){
							actions.push('<a class="btn btn-success btn-xs '+staffFlag+' " href="javascript:void(0)" onclick="$.modal.openTab(\'查看\',\''+wprefix+'/show/' + row.wenjuanId + '\')"> 开始答题</a>  ');
						} 
						if(row.status == 1){
							actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="$.modal.openTab(\'查看\',\''+prefix+'/show/' + row.id + '\')"> 查看答题</a>  ');
							actions.push('<a class="btn btn-success btn-xs '+pingfenFlag+' " href="javascript:void(0)" onclick="$.modal.openTab(\'查看\',\''+pingfenprefix+'?pid=' + row.id + '\')"> 查看评分</a>  ');
						} 
                         actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>